package com.neo.service.outputExcel;




import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neo.service.outputExcel.outputUtil.ExcelBean;
import com.neo.service.outputExcel.outputUtil.ExcelUtils;
import com.neo.service.outputExcel.outputUtil.JsGridReportBase;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.zip.ZipOutputStream;

/**
 * @author 杨贵森
 * @ClassName:OutPutService
 * @Title: OutPutService
 * @Description: TODO
 * @date 2017/3/28
 */
@Service
@Transactional
public class OutPutService {



    public void outPutExcel(List list, String title, String[] hearders,String[] fields, String  creater,HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType("application/octet-stream; charset=utf-8");
        response.setHeader("Content-Disposition", "attachment; filename=" +title);

        ZipOutputStream zout = ExcelUtils.createZipStream(response,title); //创建压缩输出流
        ExcelBean bean = new ExcelBean();
        bean.setTitle(title);
        bean.setCreator(creater);
        bean.setList(list);
        bean.setHearders(hearders);
        bean.setFields(fields);
        try {
            JsGridReportBase report = new JsGridReportBase(request, response);
            report.exportToExcel(zout,bean);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            zout.close();// 关闭压缩输出流
        }
    }


}
